/**
 * Created by hcadmin on 16/3/24.
 */

define([
    "jquery",
    "IO",
    "bootbox",
],function($,IO,bootbox){
    $(function(){
        var grid;
        var columns=[
            {
                title:'轮播图',
                dataIndex:'pic',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span><img src='" + data[datarow].url + "' width='80px;' height='80px;'></span>"+"</span>";
                }
            },
            {
                title: '操作',
                dataIndex: 'action',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span><a href='javascript:void(0)' style='color: red;' class='delete' pic_id='"+data[datarow].pic_id+"'>删除</a></span>";
                }
            },
        ];

        function dataInit() {
            grid = new Grid("/pte/api/pic", $("#table_my_toast"), $("#paging_my_toast"), 1, 10, columns, get_input_param(), 10);

            //初始化
            grid.Init();
        }
        function get_input_param() {
            var param="";
            return param;
        }
        dataInit();
        //删除课程
        $(document).on("click",".delete",function(){
            var pic_id=$(this).attr("pic_id");
            if(pic_id){
                bootbox.confirm("确定要删除该轮播图片？",function(result){
                    if(result) {
                        IO.get("act/pic_delete",{pic_id:pic_id},function(d){
                            bootbox.alert(d.msg,function(){
                                if (d.code == 0) {
                                    location.href = '/pte/pic_list';
                                }
                            })
                        });
                    }
                });
            }
        });
    })
})
